package com.dycong.common.IO.calculator.bio;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * Created by dycong on 2017/3/24.
 */
public class ServerReader implements Runnable {
    private Socket socket;
    public ServerReader(Socket socket) {
        this.socket = socket;
    }
    @Override
    public void run() {
        BufferedReader in = null;
        try{
            in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

            String expression;
            String result;
            while(true){
                if((expression = in.readLine())!=null)
                System.out.println("server循环读: " + expression);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            //һЩ��Ҫ��������
            if(in != null){
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                in = null;
            }
            if(socket != null){
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                socket = null;
            }
        }
    }
}
